//
// Created by steven on 2017/2/27.
// Copyright (c) 2017 steven. All rights reserved.
//

#import "GMAccountTableViewCell.h"


@implementation GMAccountTableViewCell

- (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier {
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        [self setupMainView];
        self.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
    }

    return self;
}

- (void)setupMainView {
    [self addSubview:self.avatarImageView];
    [self addSubview:self.nameImageIcon];
    [self addSubview:self.phoneImageIcon];
    [self addSubview:self.nameLabel];
    [self addSubview:self.phoneLabel];

    // avatar image view
    [self.avatarImageView autoAlignAxisToSuperviewAxis:ALAxisHorizontal];
    [self.avatarImageView autoPinEdgeToSuperviewEdge:ALEdgeLeading withInset:24];
    [self.avatarImageView autoSetDimensionsToSize:CGSizeMake(50, 50)];

    // name icon
    [self.nameImageIcon autoPinEdge:ALEdgeTop toEdge:ALEdgeTop ofView:self.avatarImageView];
    [self.nameImageIcon autoPinEdge:ALEdgeLeading toEdge:ALEdgeTrailing ofView:self.avatarImageView withOffset:45];

    // name label
    [self.nameLabel autoAlignAxis:ALAxisHorizontal toSameAxisOfView:self.nameImageIcon];
    [self.nameLabel autoPinEdge:ALEdgeLeading toEdge:ALEdgeTrailing ofView:self.nameImageIcon withOffset:8];

    // phone icon
    [self.phoneImageIcon autoPinEdge:ALEdgeBottom toEdge:ALEdgeBottom ofView:self.avatarImageView];
    [self.phoneImageIcon autoPinEdge:ALEdgeLeading toEdge:ALEdgeTrailing ofView:self.avatarImageView withOffset:45];

    // phone label
    [self.phoneLabel autoAlignAxis:ALAxisHorizontal toSameAxisOfView:self.phoneImageIcon];
    [self.phoneLabel autoPinEdge:ALEdgeLeading toEdge:ALEdgeTrailing ofView:self.phoneImageIcon withOffset:8];
}

- (UIImageView *)avatarImageView {
    if (!_avatarImageView) {
        _avatarImageView = [[UIImageView alloc] init];
    }
    return _avatarImageView;
}

- (UIImageView *)nameImageIcon {
    if (!_nameImageIcon) {
        _nameImageIcon = [[UIImageView alloc] init];
        _nameImageIcon.image = [UIImage imageNamed:@"name-small-icon"];
    }

    return _nameImageIcon;
}

- (UIImageView *)phoneImageIcon {
    if (!_phoneImageIcon) {
        _phoneImageIcon = [[UIImageView alloc] init];
        _phoneImageIcon.image = [UIImage imageNamed:@"phone-small-icon"];
    }

    return _phoneImageIcon;
}

- (UILabel *)nameLabel {
    if (!_nameLabel) {
        _nameLabel = [[UILabel alloc] init];
//        _nameLabel.font = [UIFont systemFontOfSize:12];
    }
    return _nameLabel;

}

- (UILabel *)phoneLabel {
    if (!_phoneLabel) {
        _phoneLabel = [[UILabel alloc] init];
//        _phoneLabel.font = [UIFont systemFontOfSize:12];
    }
    return _phoneLabel;
}

@end